#ifdef WIN32
  #include <windows.h>
#endif

#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>

#include "WA_MainWin.h"

int main(int argc, char *argv[])
{
	int appResult;
    QApplication app(argc, argv);

#ifdef WIN32
  #ifndef QT_NO_DEBUG
	// DBG
	// Create a win32 console for printfing
	AllocConsole();

	freopen("CONIN$","rb",stdin);   // reopen stdin handle as console window input
	freopen("CONOUT$","wb",stdout);  // reopen stout handle as console window output
	freopen("CONOUT$","wb",stderr); // reopen stderr handle as console window output
  #endif
#endif

	// Start the main window
	WriteAttackMainWin *mainWindow = new WriteAttackMainWin();
	
	app.connect( mainWindow->getQuitAction(), SIGNAL( triggered() ),
				 &app, SLOT(quit()) );
	app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));

	mainWindow->show();
	mainWindow->startWriting();	
	
	// Exec
	appResult = app.exec();
	
	// Cleanup	
	delete mainWindow;

	// Done
	return appResult;
}
